package xin.nick;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;

/**
 * Service也可以作为单独的模块进行启动
 * @author Nick
 * @since 2024/4/12
 */
@SpringBootApplication
@Slf4j
public class SystemServiceApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(SystemServiceApplication.class, args);

        ConfigurableEnvironment environment = applicationContext.getEnvironment();

        log.info("SystemServiceApplication started!!!");
        log.info("SystemServiceApplication 启动!!!");

        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = Optional.ofNullable(environment.getProperty("server.port")).orElse("8080");
            String contextPath = Optional.ofNullable(environment.getProperty("server.servlet.context-path")).orElse("");
            log.info("http://{}:{}{}/doc.html", ip, port, contextPath);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }

}
